package com.tingyuge.plugin;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;

import java.sql.Connection;
import java.util.Properties;
import java.util.concurrent.locks.Condition;

/**
 * @author xiaodao
 * @version 1.0
 * @date 2021/6/12
 */
@Intercepts(
        @Signature(type = StatementHandler.class
        ,method = "prepare",args ={ Connection.class,Integer.class}
        )
)
public class MyPlugin implements Interceptor {
    /**
     * 拦截方法: 只有被拦截的目标对象方法被执行,这个方法就会执行
     * @param invocation
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("myPlugin executor");
        return invocation.proceed();
    }

    /**
     * //主要是为了把这个拦截器⽣成⼀个代理放到拦截器链中
     * @param target
     * @return
     */
    @Override
    public Object plugin(Object target) {
        Object wrap = Plugin.wrap(target, this);
        return wrap;
    }

    @Override
    public void setProperties(Properties properties) {
        System.out.println("插件配置的初始化参数： "+properties );
    }
}
